107B - Basketball Team - CodeForces Solution


combinatorics dp math probabilities *1600

Please click on ads to support us..

Python Code:

n, m, h = map(int, input().split())
a = list(map(int, input().split()))
ans = 1

S = sum(a)
if S < n:
    print(-1)
else:
    if S-a[h-1] < n-1:
        print(1)
    else:
        up = S-a[h-1]
        down = S-1
        
        for i in range(1, n):
            ans = ans*(up/down)
            up -= 1
            down -= 1
        
        print(1-ans)

C++ Code:

// Problem: B. Basketball Team
// Contest: Codeforces - Codeforces Beta Round #83 (Div. 1 Only)
// URL: https://codeforces.com/problemset/problem/107/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>

using namespace std;

void solve() {
    // READ QUESTION AGAIN 5 MINS AFTER YOU HAVE READ ONCE
    int N, M, H;
    cin >> N >> M >> H;
    int sum = 0;
    int curr = 0;
    for (int x = 0; x < M; x++) {
        int nb;
        cin >> nb;
        sum += nb;
        if (x == H - 1) curr = nb;
    }
    /*
    3 2 1
    2 2
    */
    if (sum < N) {
        cout << -1 << '\n';
        return;
    }
    if (sum - curr <= N - 2) {
        cout << 1 << '\n';
        return;
    }
    long double neg = 1;
    for (int x = 0; x + 1 < curr; x++) {
        neg *= (sum - N - x) / (long double)(sum - x - 1);
    }
    cout << fixed << setprecision(10) << 1 - neg << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

99A - Help Far Away Kingdom
622B - The Time
1688C - Manipulating History
1169D - Good Triple
1675B - Make It Increasing
588A - Duff and Meat
1541B - Pleasant Pairs
1626B - Minor Reduction
1680A - Minimums and Maximums
1713A - Traveling Salesman Problem
1713B - Optimal Reduction
1710A - Color the Picture
1686B - Odd Subarrays
251A - Points on Line
427C - Checkposts
1159A - A pile of stones
508A - Pasha and Pixels
912A - Tricky Alchemy
1249A - Yet Another Dividing into Teams
1713C - Build Permutation
1699A - The Third Three Number Problem
1617B - GCD Problem
841A - Generous Kefa
1690B - Array Decrements
1692C - Where's the Bishop
104A - Blackjack
1438A - Specific Tastes of Andre
1711C - Color the Picture
1194C - From S To T
110B - Lucky String